package view.sit
{
	import flash.display.DisplayObject;
	import flash.events.TimerEvent;
	
	import global.GameState;
	
	import utils.DisplayTool;
	import utils.EnterFrameTimer;
	
	import view.face.Hint;
	
	final public class SitPrompt extends Hint
	{
		private var timer:EnterFrameTimer;
		
		public function SitPrompt()
		{
			initTimer();
			super.miniWidth = 40;
		}
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(5000);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
		}
		
		private function onTimer(event:TimerEvent):void
		{
			clear();
		}
		
		public function updateContent(content:String,target:DisplayObject):void
		{
			timer.start();
			content = "<font color='#FFFFFF' size= '12'>" + content + "</font>";
			showHint(target,content,true);
			this.y += 40;
			this.x = target.x + 55 - this.width* .5;
			
			if (this.y < 0)
			{
				showHint(target,content,false);
				this.y -= 60;
				this.x = target.x + 55 - hintText.width* .5;
				drawArrow3();
			}
			else
			{
			
				if (this.x + this.width > GameState.GAME_WIDTH)
				{
					this.x = GameState.GAME_WIDTH - this.width;
				
				}
				else if (this.x < 0)
				{
					this.x = 0;
					drawArrowUp(target.x + 75);
				}
				else
				{
					drawArrow();
				}
			}
		}
		
		private var elp:int = 12;
		
		private function drawArrow3():void
		{
			with(this.graphics)
			{
				beginFill(0,.6);
				
				//drawRoundRect(-2,-2,hintText.width + 4,hintText.height + 4,12,12);
				
				
				
				moveTo(hintText.width * .7 + 4,hintText.y - 2);
				lineTo(hintText.width * .7 - 14 + 4,hintText.y - 2);
				lineTo(hintText.width * .7 - 7 + 4,hintText.y - 14);
		
				lineTo(hintText.width * .7 + 4,hintText.y - 2);
				endFill();
			}
		}
		
		private function drawArrowUp(x:int):void
		{
			with(this.graphics)
			{
				
				clear();
				lineStyle(1,0xAAAAAA);
				beginFill(0,.6);
				
				moveTo(elp,0);
				lineTo(this.width - elp,0);
				curveTo(this.width,0,this.width,elp);
				lineTo(this.width,hintText.height - elp);
				curveTo(this.width,hintText.height,this.width - elp,hintText.height);
				lineTo(x * .5 + 10,hintText.height);
				lineTo(x * .5 + 5 , hintText.height + 10);
				lineTo(x * .5, hintText.height);
				lineTo(elp,hintText.height);
				curveTo(0,hintText.height,0,hintText.height - elp);
				lineTo(0,elp);
				curveTo(0,0,elp,0);
				
				/*beginFill(0,.6);
				moveTo(x * .7 + 4,hintText.height + 2);
				lineTo(x * .7 - 14 + 4,hintText.height + 2);
				lineTo(x * .7 - 7 + 4,hintText.height + 14);
		
				lineTo(x * .7 + 4,hintText.height + 2);*/
				endFill();
			}
		}
		
		private function drawArrow():void
		{
			with(this.graphics)
			{
				clear();
				lineStyle(1,0xAAAAAA);
				beginFill(0,.6);
				
				moveTo(elp,0);
				lineTo(this.width - elp,0);
				curveTo(this.width,0,this.width,elp);
				lineTo(this.width,hintText.height - elp);
				curveTo(this.width,hintText.height,this.width - elp,hintText.height);
				lineTo(this.width * .5 + 10,hintText.height);
				lineTo(this.width * .5 + 5 , hintText.height + 10);
				lineTo(this.width * .5, hintText.height);
				lineTo(elp,hintText.height);
				curveTo(0,hintText.height,0,hintText.height - elp);
				lineTo(0,elp);
				curveTo(0,0,elp,0);
				
				/*moveTo(hintText.width * .7 + 4,hintText.height + 2);
				lineTo(hintText.width * .7 - 14 + 4,hintText.height + 2);
				lineTo(hintText.width * .7 - 7 + 4,hintText.height + 14);

				lineTo(hintText.width * .7 + 4,hintText.height + 2);*/
				endFill();
			}
		}
		
		override protected function drawBg() : void
		{
			with(this.graphics)
			{
				clear();
				lineStyle(1,0xCCCCCC);
				beginFill(0,.6);
				//drawRoundRect(-2,-2,hintText.width + 4,hintText.height + 4,12,12);
				
				
				
				
				endFill();
			}
		}
		
		public function clear():void
		{
			timer.stop();
			DisplayTool.removeChild(this.parent,this);
		}
	}
}